<?php
/**
 * Do not modify. Just use the MVC!
 */

function __autoload($class)
{
	$file = str_replace('_', '/', $class) . '.php';
	if (file_exists('rpd/' . $file))
	{
		require_once 'rpd/' . $file;
	}
	else
	{
		require_once $file;
	}
}

require_once 'Config/bootstrap.php';
require_once 'Config/db.php';
require_once 'Config/plugin.php';

foreach ($config_plugin as $o)
{
	$o->startup();
}

if (!isset($_SERVER['REDIRECT_URL']) || $_SERVER['REDIRECT_URL'] == '/')
{
	$_SERVER['REDIRECT_URL'] = '/index';
}
else
{
	$i = 0;
	while (
		   !file_exists('View' . $_SERVER['REDIRECT_URL'] . '.php')
		&& !file_exists('Controller' . $_SERVER['REDIRECT_URL'] . '.php')
		&& $_SERVER['REDIRECT_URL'] != '')
	{
		$val = strrchr($_SERVER['REDIRECT_URL'], '/');
		$_SERVER['REDIRECT_URL'] = substr($_SERVER['REDIRECT_URL'], 0, -strlen($val));

		$var = strrchr($_SERVER['REDIRECT_URL'], '/');
		$_SERVER['REDIRECT_URL'] = substr($_SERVER['REDIRECT_URL'], 0, -strlen($var));

		$_GET[strtolower(substr($var, 1))] = urldecode(substr($val, 1));
	}
}

if ($_SERVER['REDIRECT_URL'] == '')
{
	$_SERVER['REDIRECT_URL'] = '/index';
}

foreach ($config_plugin as $o)
{
	$o->pre();
}

if (file_exists('Controller' . $_SERVER['REDIRECT_URL'] . '.php'))
{
	require_once 'Controller' . $_SERVER['REDIRECT_URL'] . '.php';
}
else
{
	require_once 'View' . $_SERVER['REDIRECT_URL'] . '.php';
}

$key = array_keys($config_plugin);
$i = count($key)-1;
for ($i; $i >= 0; $i--)
{
	$config_plugin[$key[$i]]->post();
}

$i = count($key)-1;
for ($i; $i >= 0; $i--)
{
	$config_plugin[$key[$i]]->shutdown();
}
?>